//-----------------------------------------------------------------------
// <copyright file="a_Surveys_CommentDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_Surveys_CommentDAOBase
    {
        #region Common methods
        public virtual a_Surveys_Comment Createa_Surveys_CommentFromReader(IDataReader reader)
        {
            a_Surveys_Comment item = new a_Surveys_Comment();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("ID"))) item.ID = (int)reader["ID"];
                if (!reader.IsDBNull(reader.GetOrdinal("QID"))) item.QID = (int)reader["QID"];
                if (!reader.IsDBNull(reader.GetOrdinal("Comment"))) item.Comment = (string)reader["Comment"];
                if (!reader.IsDBNull(reader.GetOrdinal("DateCreated"))) item.DateCreated = (DateTime)reader["DateCreated"];
                if (!reader.IsDBNull(reader.GetOrdinal("CookieID"))) item.CookieID = (string)reader["CookieID"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_Surveys_Comment methods
            
        public virtual void Createa_Surveys_Comment(a_Surveys_Comment a_Surveys_Comment)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Surveys_Comments_ins");
                
                database.AddInParameter(dbCommand, "@QID", DbType.Int32, a_Surveys_Comment.QID);
                database.AddInParameter(dbCommand, "@Comment", DbType.String, a_Surveys_Comment.Comment);
                database.AddInParameter(dbCommand, "@DateCreated", DbType.DateTime, a_Surveys_Comment.DateCreated);
                database.AddInParameter(dbCommand, "@CookieID", DbType.AnsiString, a_Surveys_Comment.CookieID);
                database.AddOutParameter(dbCommand, "@ID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_Surveys_Comment.ID = (int)database.GetParameterValue(dbCommand, "@ID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_Surveys_Comment methods
        
        public virtual void Updatea_Surveys_Comment(a_Surveys_Comment a_Surveys_Comment)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Surveys_Comments_upd");            
                
                database.AddInParameter(dbCommand, "@ID", DbType.Int32, a_Surveys_Comment.ID);
                database.AddInParameter(dbCommand, "@QID", DbType.Int32, a_Surveys_Comment.QID);
                database.AddInParameter(dbCommand, "@Comment", DbType.String, a_Surveys_Comment.Comment);
                database.AddInParameter(dbCommand, "@DateCreated", DbType.DateTime, a_Surveys_Comment.DateCreated);
                database.AddInParameter(dbCommand, "@CookieID", DbType.AnsiString, a_Surveys_Comment.CookieID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_Surveys_Comment methods
        public virtual void Deletea_Surveys_Comment(int id)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Surveys_Comments_del");
                
                database.AddInParameter(dbCommand, "@ID", DbType.Int32, id);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_Surveys_Comment methods
        
        public virtual a_Surveys_Comment Geta_Surveys_Comment(int id)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Surveys_Comments_sel");
                
                database.AddInParameter(dbCommand, "@ID", DbType.Int32, id);
                
                a_Surveys_Comment a_Surveys_Comment =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_Surveys_Comment = Createa_Surveys_CommentFromReader(reader);
                        reader.Close();
                    }
                }
                return a_Surveys_Comment;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_Surveys_CommentList methods
        public virtual a_Surveys_CommentCollection Geta_Surveys_CommentList(a_Surveys_CommentColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Surveys_Comments_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_Surveys_CommentCollection a_Surveys_CommentCollection = new a_Surveys_CommentCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_Surveys_Comment a_Surveys_Comment = Createa_Surveys_CommentFromReader(reader);
                        a_Surveys_CommentCollection.Add(a_Surveys_Comment);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_Surveys_CommentCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_Surveys_CommentCollection Geta_Surveys_CommentList(a_Surveys_CommentColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_Surveys_CommentList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion

        #region Geta_Surveys_CommentList_qid methods
        public virtual a_Surveys_CommentCollection Geta_Surveys_CommentList_qid(int qid, a_Surveys_CommentColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Surveys_Comments_selList_qid");
                database.AddInParameter(dbCommand, "@QID", DbType.Int32, qid);
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);

                a_Surveys_CommentCollection a_Surveys_CommentCollection = new a_Surveys_CommentCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_Surveys_Comment a_Surveys_Comment = Createa_Surveys_CommentFromReader(reader);
                        a_Surveys_CommentCollection.Add(a_Surveys_Comment);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_Surveys_CommentCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public virtual a_Surveys_CommentCollection Geta_Surveys_CommentList_qid(int qid, a_Surveys_CommentColumns orderBy, OrderDirection orderDirection)
        {
            int totalRecords = 0;
            return Geta_Surveys_CommentList_qid(qid, orderBy, orderDirection, 0, 0, out totalRecords);
        }

        #endregion
    }
}